/********************
uart.h
2011-04-25
********************/
#ifndef _PHY_H
#define _PHY_H
/*-------------------------------------------------
Includes
-------------------------------------------------*/
#include "timer.h"
#include "general.h"
#include "msg_queue.h"
#include "msg.h"
#include "uart.h"
/*-------------------------------------------------
Defines
-------------------------------------------------*/
//#define T2_FREQ				10000			//Timer2 Int, for MAC Access
#define	PARITY_ERR_TOL		10				// byte+parity check, maximum error, CONSIDERING TOLERANCE OF EOP!!!
#define PLC_BUFFER_LENGTH	255
#define TX_ON()				P32 = 0;
#define	TX_OFF()			P32 = 1;

/*-------------------------------------------------
External Variances
-------------------------------------------------*/
extern bit plcXmtGoing;

extern unsigned char 	plcRcvValid[];		// meanning 1:bpsk valid; 2:ds15 valid: 3:ds63 valid
extern unsigned char 	plcRcvError[];		// 1: sync fail; 2: eop fail
extern unsigned char 	plcRcvLen[];
extern unsigned char 	plcRcvInfo[];
extern unsigned char	plcRcvParityErr[];
extern unsigned char	plcRcvErrMsg[];		// error msg debug
extern unsigned char xdata plcRcvBuffer[4][PLC_BUFFER_LENGTH];

/*-------------------------------------------------
External Interfaces
-------------------------------------------------*/
void PhyInit();

unsigned char OldPLCSend(unsigned char* pt, unsigned char dataLen,unsigned char mode);
unsigned char PlcSend(unsigned char * pHead, unsigned int bytes, unsigned char mode);

bool plc_intial(unsigned char xmt_ctrl);
bool plc_send_byte(unsigned char out_data);
bool PlcSendFrameEnd();
bool PlcSendSuccess();
bool disable_plc();

bool proc_plc_msg();
bool get_plc_data();

#endif